/* author: Tri.Nguyen */

jQuery.fn.iBlock = function(opts) {
	return this.iUnblock().each(function(){
		var $element = jQuery(this);
		$element.attr('readonly', 'readonly');
		var position = $element.position();
		if(opts.img != null){
			var blockUIIconTop = position.top + $element.height()/2;
			var blockUIIconLeft = position.left + $element.width()/2;
			var $blockUIIcon = jQuery("<img src='"+opts.img+"' class='blockUI'/>");
			$blockUIIcon.css({
				position: 'absolute',
				top: blockUIIconTop,
				left: blockUIIconLeft
			});		
			$element.after($blockUIIcon);
		}
		
		var blockUIOverlayWidth = ($element.width() + 5) + 'px';
		var blockUIOverlayHeight = ($element.height() + 5) + 'px';
		var blockUIOverlayTop = position.top;
		var blockUIOverlayLeft = position.left;
		var $blockUIOverlay = jQuery("<div class='blockUI'></div>");
		$blockUIOverlay.css({
			position: 'absolute',
			zIndex: 1000,
			top: blockUIOverlayTop,
			left: blockUIOverlayLeft,
			width: blockUIOverlayWidth,
			height: blockUIOverlayHeight			
		});			
				
		$element.after($blockUIOverlay);
	});
};

jQuery.fn.iUnblock = function(opts) {
	return this.each(function() {
		var $this = jQuery(this);
		$this.removeAttr('readonly');
		$this.nextAll(".blockUI").remove();
	});
};